package schoolWork;

import javax.swing.*;
import java.awt.*;

public class ChessBoardApp extends JFrame {
    public ChessBoardApp() {
        setTitle("Chess Board");
        setSize(400, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(new GridLayout(8, 8));

        Color color1 = Color.BLACK;
        Color color2 = Color.WHITE;

        for (int i = 0; i < 8; i++) {
            Color temp = color1;
            color1 = color2;
            color2 = temp;

            for (int j = 0; j < 8; j++) {
                JButton button = new JButton();
                if ((i + j) % 2 == 0) {
                    button.setBackground(color1);
                } else {
                    button.setBackground(color2);
                }
                panel.add(button);
            }
        }

        add(panel);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                ChessBoardApp app = new ChessBoardApp();
                app.setVisible(true);
            }
        });
    }
}
